#! /usr/bin/env python
# -*- coding: utf-8 -*-

import rospy
from helloworld.srv import add_numbersRequest,add_numbers,add_numbersResponse
import sys

if __name__ == "__main__":

    if len(sys.argv) != 3:
        rospy.logerr("please input the correct parameters")
        sys.exit(1)

    #initialize ROS node
    rospy.init_node("Client1")

    #Create Client Service
    client = rospy.ServiceProxy("add_numbers",add_numbers)

    #Wait for Server to initialize
    client.wait_for_service()
    
    #Input request data
    req = add_numbersRequest()
    req.num1 = int(sys.argv[1])
    req.num2 = int(sys.argv[2])

    '''
    argv[0]  filename
    argv[1]  num1
    argv[2]  num2
    '''
    #send a request, and get the response
    #resp is the Response part of add_numbers.srv
    resp = client.call(req)

    rospy.loginfo("received response from server :%d",resp.sum)
